package homework6;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;

public class Choose {
	public Choose() {
		 try{
		      Class.forName("com.mysql.cj.jdbc.Driver");   
		    }
		    catch (Exception e) {
		      e.printStackTrace();
		    }

	}
	//INSERT INTO `correlation` (`Stu_ID`, `Tea_ID`) VALUES ('201627010120', '001')
	public boolean SchooseT(String sID,String tID) {
		boolean s=false;
		try {
	        Connection connect = DriverManager.getConnection(
	            "jdbc:mysql://localhost:3306/student","root","root");
	             //连接URL为   jdbc:mysql//服务器地址/数据库名  ，后面的2个参数分别是登陆用户名和密码
	        //"INSERT INTO teacher VALUES(?,?)"
	        String sql="insert into correlation values(?,?)";//生成一条SQL语句
	        PreparedStatement pstmt=connect.prepareStatement(sql);//创建Statement对象
	        pstmt.setString(1,sID);
	        pstmt.setString(2,tID);
	        int result=pstmt.executeUpdate();//执行SQL语句
	        if(result==1) {
	        	s=true;
	        }
	        else {
	        	s=false;
	        }
	      }
	    catch (Exception e) {
	       System.out.print("get data error!");
	       e.printStackTrace();
       }
		return s;
	}
	public boolean TchooseS(String tID,String sID) {
		boolean s=false;
		try {
	        Connection connect = DriverManager.getConnection(
	            "jdbc:mysql://localhost:3306/student","root","root");
	             //连接URL为   jdbc:mysql//服务器地址/数据库名  ，后面的2个参数分别是登陆用户名和密码
	        //"INSERT INTO teacher VALUES(?,?)"
	        String sql="insert into correlation values(?,?)";//生成一条SQL语句
	        PreparedStatement pstmt=connect.prepareStatement(sql);//创建Statement对象
	        pstmt.setString(1,sID);
	        pstmt.setString(2,tID);
	        int result=pstmt.executeUpdate();//执行SQL语句
	        if(result==1) {
	        	s=true;
	        }
	        else {
	        	s=false;
	        }
	      }
	    catch (Exception e) {
	       System.out.print("get data error!");
	       e.printStackTrace();
       }
		return s;
	}
}
